﻿using System.Data;
using System.Data.SqlClient;
using System;

namespace Adams.Web.Areas.MyAdams.Data.Profile
{
    public static class Password
    {
        public static Adams.Web.Areas.MyAdams.Models.Profile.Password.PageLoad PageLoad(int memberId)
        {
            return null;
        }

        public static Adams.Web.Areas.MyAdams.Models.Profile.Password.MemberInfo GetMemberInfo(int memberId)
        {
            var data = new Adams.Web.Areas.MyAdams.Models.Profile.Password.MemberInfo();

            using (SqlDataReader dr = Adams.Web.Data.DB.RunDataReader(@"
SELECT *
FROM Membership.Members
WHERE MemberID = @MemberID
", CommandType.Text,
                Adams.Web.Data.DB.CreateParameter("@MemberID", memberId)))
            {
                dr.Read();
                data.PasswordHash = dr["PasswordHash"].DbString();
                data.PasswordSalt = dr["PasswordSalt"].DbString();
            }

            return data;
        }

        public static void SavePassword(int memberId, string passwordHash)
        {
            Adams.Web.Data.DB.Run(@"
UPDATE Membership.Members SET
    PasswordHash = @PasswordHash
WHERE MemberID = @MemberID
", CommandType.Text,
                    Adams.Web.Data.DB.CreateParameter("@MemberID", memberId),
                    Adams.Web.Data.DB.CreateParameter("@PasswordHash", passwordHash));
        }
    }
}
